﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using Alserve.Ffl.Data;

public partial class ffl_anonymous_club : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Club thisClub = new Club();
            thisClub.LoadAll();
            thisClub.Sort = "ClubName";
            ClubDropDown.DataSource = thisClub.DefaultView;
            
            ClubDropDown.DataBind();

            if (Request.QueryString["cid"] != null)
                ClubDropDown.SelectedValue = Request.QueryString["cid"];
        }

        Position thisPosition = new Position();
        thisPosition.LoadAll();
        PositionRepeater.DataSource = thisPosition.DefaultView;
        PositionRepeater.DataBind();

    }

    protected void PositionRepeater_ItemDataBind(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Int32 clubId = Convert.ToInt32(ClubDropDown.SelectedValue);
            Int32 positionId = Convert.ToInt32(((HiddenField)e.Item.FindControl("PositionIdHidden")).Value);

            XmlDataSource playerDataSource = (XmlDataSource)e.Item.FindControl("PlayerDataSource");
            Repeater playerRepeater = (Repeater)e.Item.FindControl("PlayerRepeater");
            playerRepeater.DataSource = GetPlayerListFromClub(clubId, positionId);
            playerRepeater.DataBind();
        }
    }

    private DataView GetPlayerListFromClub(Int32 clubId, Int32 positionId)
    {
        _PlayerView thisPlayerView = new _PlayerView();
        thisPlayerView.Where.ClubId.Value = clubId;
        thisPlayerView.Where.PositionId.Value = positionId;
        if (Alserve.Ffl.FflCommon.InRunning())
        {
            thisPlayerView.Where.TotalPoints.Value = 0;
            thisPlayerView.Where.TotalPoints.Operator = MyGeneration.dOOdads.WhereParameter.Operand.GreaterThan;
        }
        thisPlayerView.Sort = _PlayerView.ColumnNames.TotalPoints + " DESC";
        thisPlayerView.Sort = _PlayerView.ColumnNames.Surname + " ASC";
        thisPlayerView.Query.Load();

        return thisPlayerView.DefaultView;
        
    }


   
}
